// api.js
import {
	request
} from '@/utils/request.js'; // 引入封装好的request.js
//获取订单列表
export const getOrderList = (data) => {
	return request({
		url: '/order/getPage',
		method: 'POST',
		data: data,
	});
};
//下单
export const addOrder = (data) => {
	return request({
		url: '/order/createOrder',
		method: 'POST',
		data: data,
	});
};
//获取订单金额
export const getOrderAmount = (data) => {
	return request({
		url: '/order/concession_amount_calculation',
		method: 'POST',
		data: data,
	});
};
//判断是否可下单
export const getInvitationRecord = (data) => {
	return request({
		url: '/invitation_record/getPage',
		method: 'POST',
		data: data,
	});
};
//修改订单状态
export const editOrder = (data) => {
	return request({
		url: '/order/updateById',
		method: 'POST',
		data: data,
	});
};

//未取消或者未付款超时的订单继续支付
export const addPayment = (orderNumber, tradeType) => {
	return request({
		url: `/order/order_continuation_payment/h5/${orderNumber}?tradeType=${encodeURIComponent(tradeType)}`, // 使用模板字符串并正确插入 id 和 tradeType
		method: 'GET',
	});
};
//取消订单
export const cancellOrder = (orderNumber) => {
	return request({
		url: `/order/cancellation_of_order/${orderNumber}`, // 使用模板字符串并正确插入 id
		method: 'GET',
	});
};
//删除订单
export const delOrder = (data) => {
	return request({
		url: `/order/updateById`, // 使用模板字符串并正确插入 id
		method: 'POST',
		data: data,
	});
};
//根据id查询订单详情
export const getOrderDetail = (id) => {
	return request({
		url: `/order/getById/${id}`, // 使用模板字符串并正确插入 id
		method: 'GET',
	});
};
//加入购物车
export const addShopping = (data) => {
	return request({
		url: '/commodity_shopping_trolley/save',
		method: 'POST',
		data: data,
	});
};
//根据ids获取购物车
export const getShoppingIds = (ids) => {
	return request({
		url: `/commodity_shopping_trolley/getByIds/${ids}`, // 使用模板字符串并正确插入 id
		method: 'GET',
	});
};
//获取购物车列表
export const getShopping = (data) => {
	return request({
		url: '/commodity_shopping_trolley/getPage',
		method: 'POST',
		data: data,
	});
};
//修改购物车
export const editShopping = (data) => {
	return request({
		url: '/commodity_shopping_trolley/updateById',
		method: 'POST',
		data: data,
	});
};

//删除购物车
export const deleteShopping = (ids) => {
	// 确保 ids 是一个逗号分隔的字符串
	const idsString = Array.isArray(ids) ? ids.join(',') : ids;

	return request({
		url: `/commodity_shopping_trolley/removeBathByIds/${encodeURIComponent(idsString)}`, // 使用模板字符串并正确插入 id
		method: 'GET', // 更改方法为 DELETE
	});
};